
package org.jma.app.ewisdom.entities;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

import org.jma.lib.soap.utils.XMLSerializable;

import com.thoughtworks.xstream.XStream;
/**
 * FileLocator class is used to store information about where we can find
 * a File. It stores:
 * <ul>
 * <li>url where we can download the file
 * <li>host not used
 * <li>port not used
 * </ul>
 * @author Jesus Mari, jesmari@ono.com
 * @version 1.0
 * @since 1.0
 */

public class FileLocator implements Serializable,XMLSerializable{
	String hostName;
	int port;
	String url;
	/**
	 * @return the url
	 */
	public String getUrl() {
		return url;
	}
	/**
	 * @param url the url to set
	 * @throws UnsupportedEncodingException 
	 */
	public void setUrl(String url) throws UnsupportedEncodingException {
		this.url = url;
	}
	/**
	 * @return the hostName
	 */
	public String getHostName() {
		return hostName;
	}
	/**
	 * @param hostName the hostName to set
	 */
	public void setHostName(String hostName) {
		this.hostName = hostName;
	}
	/**
	 * @return the port
	 */
	public int getPort() {
		return port;
	}
	/**
	 * @param port the port to set
	 */
	public void setPort(int port) {
		this.port = port;
	}


    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;

        FileLocator otherLocator = (FileLocator) o;

        if (hostName != null && otherLocator.getHostName()!=null){
        	if(!hostName.equals(otherLocator.getHostName())) return false;
   
        } else return false;
        	
        if (port != -1 && otherLocator.getPort()!=-1){
        	if(port!=otherLocator.getPort()) return false;
        } else return false;
        if (url != null && otherLocator.getUrl()!=null){
        	if(!url.equals(otherLocator.getUrl())) return false;
        } else return false;
        
        return true;
    }
    
	/**
	 * @see org.jma.lib.soap.utils.XMLSerializable
	 */
    public String serializeToXML() {
    	XStream xstream = new XStream();
    	return xstream.toXML(this);
    }
}
